<?php

/**
 * File: libs/json_writer.php
 *
 * Creates the json output
 *
 * @author     Philipp Petzold <pp@dezign.de>
 * @version    1.0
 */

class JSONWriter {

	// singleton instance object
	private static $instance;

    /**
     *  do nothing
     * 
     *  @return  void
     */
    private function __construct()
    {
        // ...
    }

    /**
     *  output the given status code and params as json
     *
     *  @param   array   $status       status code and message
     *  @param   array   $params       individually params
     * 
     *  @return  boolean               dberror status
     */
    public function output($status, $params)
    {
        $status['params'] = $params;
        header('Content-Type: application/json');
        echo json_encode($status);
        exit();
    }

    /**
     *  static instance return for singleton
     * 
     *  @return  JSONWriter                singleton instance
     */
    public static function getInstance()
    {
        if (!self::$instance)
        {
            self::$instance = new JSONWriter();
        }
        return self::$instance;
    } 
}

?>